const crawler = require('../../libs/crawler'),
      { crawlerConf } = require('../../config/config');

crawler({

  url: crawlerConf.url.teacher,
  callback () {
    const $ = window.$,
          $item = $('.tea');
    
    const data = [];

    $item.each((index, item) => {
      const $el = $(item);
          
      const dataItem = {
        tid: index + 1,
        href: $el.find('.tea-face').prop('href'),
        teacherName: $el.find('.tea-face').prop('title'),
        teacherImgUrl: 'http:' + $el.find('img').attr('lazy-src').replace('webp', ''),
        //这里用了CD的懒加载，爬取src会缺失，必须爬取lazy-src里的内容
        //上传七牛云的图片要拼接成http: //dxxxx的格式，能直接访问的格式
        courseCount: parseInt($el.find('.tea-main-sub span').eq(0).text().replace(/[^0-9]/ig, '')),
        studentCount: parseInt($el.find('.tea-main-num').text().replace(/[^0-9]/ig, '')),
        intro: $el.find('.tea-main-cnt').prop('title'),
        teacherImgKey: ''
      };

      data.push(dataItem);
    }); 

    return data;
  }

})